// pages/navDetail/navDetail.js
var request = require("../../utils/request.js");
var pro_list = []

Page({

  /**
   * 页面的初始数据
   */
  data: {
    indicatorDots: false,
    autoplay: false,
    interval: 3000,
    duration: 1000,
    circular: true,
    isclick: false,
    isclickTap: false,
    id: '',
    pro_list: '',
    major_list: '',
    isCLICK: false,
    isarea:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    var that = this;
    wx.setNavigationBarTitle({
      title: options.title
    })

    that.setData({
      id: options.id
    })

    that.getData();

  },
  // 获取数据
  getData: function () {
    var that = this;
    var url = request.dataUrl + '/api/index/details';
    var params = {
      id: that.data.id,
      status: 1
    }
    request.requestLoading(url, params, '正在加载数据', function (res) {
      console.log(res)
      if (res.code == 0) {
        that.setData({
          comment_list: res.msg.comment_list,
          profession_list: res.msg.profession_list,
          school_details: res.msg.school_details
        })
      } else {
        wx.showLoading({
          title: '数据加载中...',
        })
      }

    }, function (res) {
      wx.showToast({
        title: '加载数据失败',
      })
    })
  },
  //获取学校或专业图集
  getPhotos: function () {
    var that = this;
    var url = request.dataUrl + '/api/index/img_list';
    var params = {
      school_id: that.data.id  
    }
    request.requestLoading(url, params, '正在加载数据', function (res) {
      console.log(res)
      if (res.code == 0) {
        that.setData({   
          img_lis:res.msg
        })
      } else {
        wx.showLoading({
          title: '数据加载中...',
        })
      }

    }, function (res) {
      wx.showToast({
        title: '加载数据失败',
      })
    })
  },
  // 获取个人数据
  getDataInfo: function () {
    var that = this;      
    wx.request({
        url: request.dataUrl + '/api/index/get_school_sign',
      data: {
        session3rd: wx.getStorageSync('session3rd'),
        school_id: that.data.id
      },      
      method:'POST',    
      success: function(res) {
        if (res.data.code == 0) {
          if (res.data.msg.user_name == "" || res.data.msg.user_number == "") {
            wx.showToast({
              title: '请完善个人信息',
              image: "../../image/fail.png",
              duration: 1500,
              success:function(){
                setTimeout(function(){
                  wx.navigateTo({                                    
                    url: '../personInfo/personInfo',                  
                  })
                },2000)
              }
            })
            that.setData({
              isclickTap: false
            })
          } else {
            that.setData({
              dataInfo: res.data.msg,
              pro_list: res.data.msg.pro_list,
              major_list: res.data.msg.pro_list[0],
              isclickTap: true
            })
          }

        } else {
          wx.showLoading({
            title: '数据加载中...',
          })
        }

      },
      fail: function(res) {
        wx.showToast({
          title: '加载数据失败',
        })
      }
    
    })

   
  },
  // 
  bindtextarea(e){
      var that=this;
      that.setData({
        isarea:true
      })
  },
  // 提交评价
  formSubmit(e) {
    // console.log(e)
    var that = this;
    wx.request({
      url: request.dataUrl + '/api/index/set_com',
      data: {
        session3rd: wx.getStorageSync('session3rd'),
        school_id: that.data.id,
        com_content: e.detail.value.textarea
      },
      method: 'post',
      success: function (res) {
        console.log(res)
        if (res.data.code == 0) {
          wx.showToast({
            title: '提交成功',
            image: '../../image/success.png',
            duration: 1500
          })
          that.getData();
          that.setData({
            value:'',   
            isarea:false         
          })

        } else {
          wx.showToast({
            title: '提交失败',
            image: '../../image/fail.png',
            duration: 1500
          })
        }
      }
    })
  },
  //提交个人专业信息
  formMit(e) {
    var that = this;
    console.log(e)
    console.log(that.data.major_lis)
    if (that.data.major_lis == undefined){
      wx.showToast({
        title: '请输入专业',
        image: '../../image/fail.png',
        duration: 1500
      })
    } else {

      wx.request({
        url: request.dataUrl + '/api/index/insert_sign',
        data: {
          session3rd: wx.getStorageSync('session3rd'),
          school_id: that.data.id,
          pro_id: that.data.major_list.pro_id,
          wechat_number: e.detail.value.wxNum
        },
        method: 'POST',
        success: function (res) {
          console.log(res)
          if (res.data.code == 0) {
            wx.showToast({
              title: res.data.msg,
              image: '../../image/success.png',
              duration: 1500,
              success: function () {
                setTimeout(function () {
                  that.setData({
                    isclickTap: false
                  })
                }, 2000)
              }
            })
          } else {
            wx.showToast({
              title: res.data.msg,
              image: '../../image/fail.png',
              duration: 1500
            })
          }
        }
      })

    }
  },

  //下拉框的内容区
  pick_clumn: function () {
    var that = this;

    var animation = wx.createAnimation({
      duration: 500,
      timingFunction: 'ease-in-out',
    });
    that.animation = animation;
    animation.translateY(-285).step();
    that.setData({
      animationData: that.animation.export(),
      maskVisual: 'show',
      condition: !that.data.condition
    });
  },
  cascadeDismiss: function () {
    this.animation.translateY(285).step();
    this.setData({
      animationData: this.animation.export(),
      maskVisual: 'hidden',
      condition: !this.data.condition
    });
  },
  // 专业选择
  bindChange(e) {
    var that = this;
    var majorLis = that.data.pro_list
    console.log(majorLis)
    var major = majorLis[e.detail.value[0]]
    console.log(major)
    that.setData({
      major_list: major
    })
  },
  // 隐藏专业弹窗
  opened(e) {
    var that = this;
    that.setData({
      maskVisual: 'hidden',
      condition: !this.data.condition,
      major_lis: that.data.major_list,
      isCLICK: true
    })
  },
  // 隐藏专业弹窗
  cancel(e) {
    var that = this;
    that.setData({
      maskVisual: 'hidden',
      condition: !this.data.condition
    })
  },
  //  查看图集
  checkImg(e) {
    var that = this;
    console.log(e)
    that.setData({
      isclick: true
    })

    that.getPhotos();
  },
  // 隐藏图集
  bannerImg(e) {
    var that = this;
    that.setData({
      isclick: false
    })
  },
  // 阅读全文
  readAll(e) {
    var that = this;
    wx.navigateTo({
      url: "../schoolOverview/schoolOverview?status=" + e.currentTarget.dataset.status + '&id=' + that.data.id
    })
  },
  // 招生简章
  studentsGuide(e) {
    var that = this;
    wx.navigateTo({
      url: "../studentsGuide/studentsGuide?status=" + e.currentTarget.dataset.status + '&id=' + that.data.id
    })
  },
  // 专业详情
  majorDetail(e) {
    // console.log(e)
    wx.navigateTo({
      url: '../majorDetail/majorDetail?id=' + e.currentTarget.dataset.id + '&tit=' + e.currentTarget.dataset.tit,
    })
  },
  // 查看更多专业
  moreMajor(e) {
    var that = this;
    wx.navigateTo({
      url: "../choiceMajor/choiceMajor?id=" + that.data.id
    })
  },
  // 评价列表
  Tocomment(e) {
    var that = this;
    wx.navigateTo({
      url: '../comment/comment?id=' + that.data.id,
    })
  },

  applyInfo(e) {
    var that = this;
    that.setData({
      isclickTap: false
    })
  },
  mySignup(e) {
    var that = this;
    that.getDataInfo();
   
  },

  /*,*
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})